package com.forclass;

import java.lang.reflect.Method;
import java.util.Locale;

public class Book1920Main {
    public static void main(String[] args) throws Exception {
        String fieldName = "title";
        String fieldValue = "java高级应用";
        Class<?> clazz = Class.forName("com.forclass.Book1920");
        Object obj = clazz.getDeclaredConstructor().newInstance();
        Method setMethod =  clazz.getMethod("set"+initcap(fieldName),String.class);
        setMethod.invoke(obj,fieldValue);
        Method getMethod =  clazz.getMethod("get"+initcap(fieldName));
        Object value = getMethod.invoke(obj);
        System.out.println("=====" + value);


    }

    public static  String initcap(String str) {
        if (str == null || "".equalsIgnoreCase(str)) {
            return str;
        }
        if (str.length() == 1) {
            return str.toUpperCase();
        } else {
            System.out.println("---" +str.substring(1));
            return str.substring(0,1).toUpperCase() + str.substring(1);
        }

    }
}
